<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script type="text/javascript" src="asserts/plugins/JQuery/jquery-2.1.1.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#button_id").click(function () {
                console.log($("#username").val());
                console.log($("#password").val());
                console.log($("#remember").val());
                // alert()
                $.ajax({
                    url: "http://localhost:8080/TheMall/UserServlet",
                    //是否为异步
                    async: true,
                    type: "post",
                    data: {
                        action: "login",
                        username: $("#username").val(),
                        password: $("#password").val(),
                        remember: $("#remember").val(),
                    },

                    //回调成功执行的函数
                    success: function (data) {
                        if (data.respType == "success") {
                            location.href = "index.html";
                        } else if (data.respType == "error") {
                            alert("用户名或者密码错误");
                        }
                    },
                    //失败时执行的函数
                    error:function (data) {
                    },
                    //必须执行的函数
                    complete:function () {
                        // alert("一定执行")
                    },
                    //告诉JQuery传输的数据为data对象
                   /* processDate:false,
                    contentType:false*/
                })
            })
        })
    </script>

<!--    创建对象 刷新验证码-->
    <script>
        function btn(obj) {
            obj.src = "CheckServlet?data=" + new Date()
        }
    </script>



</head>
<body>
        <form id="form">
            用户名:<input type="text" name="username" id="username"><br/>
            密码:<input type="text" name="password" id="password"><a href="forgotPassword.html">忘记密码</a><br/>
            验证码:<input type="text" name="code" id="code"><img src="CheckServlet" onclick="btn(this)"><br/>
            免登录:<input type="checkbox" name="remember" id="remember"><br/>
            <input type="button" id="button_id" value="登录">
            <a href="register.html"><input type="button" id="register_id" value="注册"></a>
        </form>
</body>
</html>